﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel.DataAnnotations;

namespace A2DFramework.ValidationService.RuleValidators
{
    public class RuleDataTypeAttribute : RuleValidationAttribute
    {
        private DataTypeAttribute checker;

        public RuleDataTypeAttribute(DataType dataType):this(string.Empty, dataType)
        {
        }
        public RuleDataTypeAttribute(string rule, DataType dataType):base(rule)
        {
            checker = new DataTypeAttribute(dataType);
        }

        public RuleDataTypeAttribute(string rule, string customDataType)
            : base(rule)
        {
            checker = new DataTypeAttribute(customDataType);
        }

        protected override ValidationResult IsValid(object value, ValidationContext validationContext)
        {
            return checker.GetValidationResult(value, validationContext);
        }
    }
}
